package com.lyh.dt.server;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

/**
 * ActiveMq消费者
 * @author liuyuhong
 */
@Component
//@ConditionalOnProperty(prefix = "spring.activemq.jms", name = "enable",havingValue = "true")
public class DtActiveMqConsumerService {

    private static final Logger logger = LoggerFactory.getLogger(DtActiveMqConsumerService.class);

    @Autowired
    private DtCoreService dtCoreService;

    @JmsListener(destination="${spring.activemq.queue-totm}")
    public void readActiveQueue(DtActiveMqBean message) throws Exception{
        logger.info(String.format("activeMq 使用 queue 模式接收到消息：%s", message.toString()));
        dtCoreService.transationHandle(message);
    }

    @JmsListener(destination="${spring.activemq.topic-torm}", containerFactory = "topicListener")
    public void readActiveTopic1(DtActiveMqBean message) throws Exception{
        logger.info(String.format("activeMq1 使用 topic 模式接收到消息：%s", message.toString()));
    }

    @JmsListener(destination="active.topic" , containerFactory = "topicListener")
    public void readActiveTopic2(String message) throws Exception{
        logger.info(String.format("activeMq2 使用 topic 模式接收到消息：%s", message));
    }
}
